<template>
  <h1>El-页面综合练习1</h1>
  <el-form style="width: 600px;margin: 0 auto;">
    <el-form-item label="姓名">
      <el-input v-model="user.name" placeholder="请输入姓名"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input v-model="user.salary" placeholder="请输入薪资"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input v-model="user.job" placeholder="请输入岗位"></el-input>
    </el-form-item>
    <el-form-item><el-button type="success" @click="onSubmit">点我提交</el-button></el-form-item>
  </el-form>
  <el-table :data="users" style="width: 600px;margin: 0 auto;">
    <el-table-column type="index" label="编号" align="center" width="80"></el-table-column>
    <el-table-column prop="name" label="姓名" align="center"></el-table-column>
    <el-table-column prop="salary" label="薪资" align="center"></el-table-column>
    <el-table-column prop="job" label="岗位" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>

import {ref} from "vue";

const user = ref({name: '', salary: '', job: ''});
const onSubmit = () => {
  users.value.push(user.value);
  user.value = {};
};
const users = ref([]);
const del = (index, row) => {
  if (confirm('确定删除' + row.name + '吗？'))
    users.value.splice(index, 1);
};
</script>

<style scoped>

</style>